package com.itheima.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itheima.mapper.StudentMapper;
import com.itheima.pojo.Student;
import com.itheima.service.StudentService;
import org.springframework.stereotype.Service;

@Service
public class StudentServiceImpl extends ServiceImpl<StudentMapper, Student> implements StudentService {

    @Override
    public void violation(Integer id, Integer score) {
        //思路是首先根据id查询到违纪的学生
        Student student = this.getById(id);
        //然后将学生的违纪次数＋1，扣分加上score
        student.setViolationCount((short) (student.getViolationCount() + 1));
        student.setViolationScore((short)(student.getViolationScore() + score));
        //设置好后，更新学生信息
        this.updateById(student);
    }
}
